package com.jx.cs.controller;


import com.jx.cs.pojo.Role;
import com.jx.cs.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@RequestMapping("role")
@Controller
public class RoleController  {

    @Autowired
    private RoleService roleService;

    //查询全部
    @ResponseBody
    @RequestMapping("selectRole")
    public Map<String,Object> selectRole(String rname ,Integer page, Integer  limit){
        Map<String, Object> map = roleService.selectRole(rname,page, limit);
        return map;

    }

    /*添加信息*/
    @ResponseBody
    @RequestMapping("addRole")
    public String addRole(Role role){
        try {
            roleService.addRole(role);
            return "ok";
        }catch (Exception e){
            e.printStackTrace();
            return "no";
        }

    }


    /*删除信息*/
    @ResponseBody
    @RequestMapping("delRole")
    public String delRole( Integer rid){
        try {
            roleService.delRole(rid);
            return "ok";
        }catch (Exception e){
            e.printStackTrace();
            return "no";
        }
    }
}
